<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        // function Person(name, age, sex) {
        //     this.name = name
        //     this.age = age
        //     this.sex = sex
        //     this.eat = function () {
        //         console.log("1223");
        //     }
        // }
        // Person.prototype.sayHi = function () {
        //     console.log("hellow");

        // }

        // function Student(weight) {
        //     this.weight = weight
        // }
        // Student.prototype = new Person('老王', 24, '男')
        // var stu1 = new Student("80kg")
        // console.dir(stu1);
        // var stu2 = new Student("90kg")
        // console.dir(stu2);
        // 借用构造函数 
        function Person(name, age, sex) {
            this.name = name
            this.age = age
            this.sex = sex
            this.eat = function () {
                console.log("1223");
            }
        }
        Person.prototype.sayHi = function () {
            console.log("hellow");

        }

        function Student(name,age,sex,weight) {
            this.weight = weight
            Person.call(this,name,age,sex)
        }
        
        var stu1 = new Student('feng',9,'naem',"80kg")
        console.dir(stu1);
        // stu1.sayHi()  // 方法丢失。
        var stu2 = new Student('feng',9,'naem',"80kg")
        console.dir(stu2);
        
    </script>
</body>

</html>